package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Controller
@RequestMapping("banner")
public class BannerController {

    @Autowired
    private IBannerService bannerService;


    //页面数据和分页
    @RequestMapping("/list")
    public String List(Model model, @ModelAttribute("qo") BannerQuery qo) {
        Page<Banner> page = bannerService.query(qo);
        model.addAttribute("page", page);
        return "banner/list";
    }

    //保存或修改
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner) {
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }


    //新增页面关联文章
    @GetMapping("/getAllType")
    @ResponseBody
    public Object getAllType() {
     Map map = bannerService.getAllType();
        return JsonResult.success(map);
    }

    //删除
    @GetMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        bannerService.delete(id);
        return JsonResult.success();
    }



}
